package com.ruoyi.caigou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.caigou.domain.dto.BuyComDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caigou.domain.BuyComparePrice;
import com.ruoyi.caigou.service.IBuyComparePriceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购比价Controller
 * 
 * @author lvql
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/buyComparePrice")
public class BuyComparePriceController extends BaseController
{
    @Autowired
    private IBuyComparePriceService buyComparePriceService;

    /**
     * 查询采购比价列表
     */
    @RequiresPermissions("caigou:buyComparePrice:list")
    @GetMapping("/list")
    public TableDataInfo list(BuyComparePrice buyComparePrice)
    {
        startPage();
        List<BuyComparePrice> list = buyComparePriceService.selectBuyComparePriceList(buyComparePrice);
        return getDataTable(list);
    }

    /**
     * 导出采购比价列表
     */
    @RequiresPermissions("caigou:buyComparePrice:export")
    @Log(title = "采购比价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyComparePrice buyComparePrice)
    {
        List<BuyComparePrice> list = buyComparePriceService.selectBuyComparePriceList(buyComparePrice);
        ExcelUtil<BuyComparePrice> util = new ExcelUtil<BuyComparePrice>(BuyComparePrice.class);
        util.exportExcel(response, list, "采购比价数据");
    }

    /**
     * 获取采购比价详细信息
     */
    @RequiresPermissions("caigou:buyComparePrice:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buyComparePriceService.selectBuyComparePriceById(id));
    }

    /**
     * 获取采购比价详细信息
     */
    @RequiresPermissions("caigou:buyComparePrice:query")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getInfoPlus(@PathVariable("id") Integer id)
    {
        return success(buyComparePriceService.selectBuyComparePriceInfoById(id));
    }

    /**
     * 新增采购比价
     */
    @RequiresPermissions("caigou:buyComparePrice:add")
    @Log(title = "采购比价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyComparePrice buyComparePrice)
    {
        return toAjax(buyComparePriceService.insertBuyComparePrice(buyComparePrice));
    }

    @RequiresPermissions("caigou:buyComparePrice:add")
    @Log(title = "采购比价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addPlus(@RequestBody BuyComDTO buyComDTO)
    {
        logger.info("BuyComparePriceController addPlus {}",buyComDTO.toString());
        return toAjax(buyComparePriceService.insertBuyComparePricePlus(buyComDTO));
//        return AjaxResult.success();
    }

    /**
     * 修改采购比价
     */
    @RequiresPermissions("caigou:buyComparePrice:edit")
    @Log(title = "采购比价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyComparePrice buyComparePrice)
    {
        return toAjax(buyComparePriceService.updateBuyComparePrice(buyComparePrice));
    }

    @RequiresPermissions("caigou:buyComparePrice:edit")
    @Log(title = "采购比价", businessType = BusinessType.UPDATE)
    @PutMapping("/upd")
    public AjaxResult editPlus(@RequestBody BuyComDTO buyComDTO)
    {
        return toAjax(buyComparePriceService.updateBuyComparePricePlus(buyComDTO));
    }


    /**
     * 删除采购比价
     */
    @RequiresPermissions("caigou:buyComparePrice:remove")
    @Log(title = "采购比价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buyComparePriceService.deleteBuyComparePriceInfoByIds(ids));
    }
}
